package cn.factorybox.common.utils.resultUtils;

/**
 * @author flypig
 * @version 1.0
 * @date 2020-03-15 15:04
 */

import cn.factorybox.common.utils.resultUtils.ExpertUtils;
import cn.factorybox.common.utils.resultUtils.MatrixCalculate;
import cn.factorybox.model.entity.JudgeValue;
import cn.factorybox.model.entity.DeviceData;

import java.util.List;

/**
 * 根据设备环境，计算result
 */
public class ResultUtils {

    public static String getResult(int type,DeviceData deviceData, List<JudgeValue> list) {
        String result = null;
        if (type == 0){
            result = indoorResult(deviceData,list);
        } else if (type == 1) {
            result = experResult(deviceData,list);
        } else if (type == 2) {
            result = outdoorResult(deviceData,list);
        }
        return result;
    }

    public static String indoorResult(DeviceData deviceData, List<JudgeValue> list) {
        double[][] R = new double[7][4];
        double[][] weightValue = new double[1][7];
        double[][] result = new double[1][4];

        // 室内的权重
        weightValue[0][0] = 0.2934;
        weightValue[0][1] = 0.0797;
        weightValue[0][2] = 0.0354;
        weightValue[0][3] = 0.2076;
        weightValue[0][4] = 0.1059;
        weightValue[0][5] = 0.1389;
        weightValue[0][6] = 0.1389;

        if (deviceData.getfTemperature() != null) {
            //进行单因素分析
            ExpertUtils.judgeTemperature_indoor(deviceData.getfTemperature(),R,list.get(0));
            ExpertUtils.judgeHumidity_indoor(deviceData.getfHumidity(),R,list.get(1));
            ExpertUtils.judgePressure_indoor(deviceData.getfPressure() ,R,list.get(2));
            ExpertUtils.judgeExhaust_indoor(deviceData.getfExhaust(),R,list.get(3));
            ExpertUtils.judgePM_indoor(deviceData.getfPm(),R,list.get(4));
            ExpertUtils.judgeCO2_indoor(deviceData.getfCarbonDioxide(),R,list.get(5));
            ExpertUtils.judgeTVOC_indoor(deviceData.getfTvoc(),R,list.get(6));

            result = MatrixCalculate.matrixMultiply(weightValue,R);

//            for (int i = 0; i < result[0].length; i++) {
//                System.out.print(i + ":" + result[0][i] + "-------");
//            }
        }
        return ExpertUtils.getResult(result);
    }

    public static String experResult(DeviceData deviceData, List<JudgeValue> list) {
        double[][] R = new double[7][4];
        double[][] weightValue = new double[1][7];
        double[][] result = new double[1][4];

        // 实验室权重
        weightValue[0][0] = 0.3126;
        weightValue[0][1] = 0.1933;
        weightValue[0][2] = 0.1117;
        weightValue[0][3] = 0.1992;
        weightValue[0][4] = 0.0441;
        weightValue[0][5] = 0.0696;
        weightValue[0][6] = 0.0696;

        if (deviceData.getfTemperature() != null) {
            //进行单因素分析
            ExpertUtils.judgeTemperature_exper(deviceData.getfTemperature(),R,list.get(0));
            ExpertUtils.judgeHumidity_exper(deviceData.getfHumidity(),R,list.get(1));
            ExpertUtils.judgePressure_exper(deviceData.getfPressure(),R,list.get(2));
            ExpertUtils.judgeExhaust_exper(deviceData.getfExhaust(),R,list.get(3));
            ExpertUtils.judgePM_exper(deviceData.getfPm(),R,list.get(4));
            ExpertUtils.judgeCO2_exper(deviceData.getfCarbonDioxide(),R,list.get(5));
            ExpertUtils.judgeTVOC_exper(deviceData.getfTvoc(),R,list.get(6));

            result = MatrixCalculate.matrixMultiply(weightValue,R);

            for (int i = 0; i < result[0].length; i++) {
                System.out.print(i + ":" + result[0][i] + "-------");
            }
        }
        return ExpertUtils.getResult(result);
    }

    public static String outdoorResult(DeviceData deviceData, List<JudgeValue> list) {
        double[][] R = new double[7][4];
        double[][] weightValue = new double[1][7];
        double[][] result = new double[1][4];

        // 实验室权重
        weightValue[0][0] = 0.5385;
        weightValue[0][1] = 0.0769;
        weightValue[0][2] = 0.0769;
        weightValue[0][3] = 0.0769;
        weightValue[0][4] = 0.0769;
        weightValue[0][5] = 0.0769;
        weightValue[0][6] = 0.0769;

        if (deviceData.getfTemperature() != null) {
            ExpertUtils.judgeTemperature_outdoor(deviceData.getfTemperature(),R,list.get(0));
            ExpertUtils.judgeHumidity_outdoor(deviceData.getfHumidity(),R,list.get(1));
            ExpertUtils.judgePressure_outdoor(deviceData.getfPressure(),R,list.get(2));
            ExpertUtils.judgeExhaust_outdoor(deviceData.getfExhaust(),R,list.get(3));
            ExpertUtils.judgePM_outdoor(deviceData.getfPm(),R,list.get(4));
            ExpertUtils.judgeCO2_outdoor(deviceData.getfCarbonDioxide(),R,list.get(5));
            ExpertUtils.judgeTVOC_outdoor(deviceData.getfTvoc(),R,list.get(6));

            result = MatrixCalculate.matrixMultiply(weightValue,R);

            for (int i = 0; i < result[0].length; i++) {
                System.out.print(i + ":" + result[0][i] + "-------");
            }
        }
        return ExpertUtils.getResult(result);
    }

}
